<?php
include_once 'field.class.php';

class field_content extends field
{
    protected $fieldname = '正文';
    public function __construct($field='')
    {
        parent::__construct($field);
        $this->field_type = 'MEDIUMTEXT';
    }

    /**
     * 生成设置项
     * @author menghao
     * @param <string> $data
     * @return <string>
     */
    function settings($data='')
    {
        $data = unserialize($data);
        $data['size'] = isset($data['size']) && is_numeric ($data['size']) ? $data['size'] : 50;
        $data['maxlength'] = isset($data['maxlength']) && is_numeric ($data['maxlength']) ? $data['maxlength'] : 60000;

        $setting = '';
        $setting .= '<label>内容最大长度(字节)：'.form::text('settings[maxlength]', 'setting_maxlength', $data['maxlength'], 7).'</label> ';

        return $setting;
    }

    function check_data($data)
    {
        if(strlen($data) > $this->field_data['settings']['maxlength'])
        {
            $this->error = "{$this->field_data['name']}最大长度不能超过 {$this->field_data['settings']['maxlength']}字节！";
            $this->response->alert($this->error);
            return false;
        }
        return parent::check_data($data);
    }

    function create_form($value='')
    {
        $field = $this->field_data['field'];
        $form = form::editor("data[$field]", $field, $value, 'standard', '95%');
        return $form;
    }
}
?>
